package net.gyapp.markim.module.contact;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.easyder.wrapper.base.view.WrapperSwipeActivity;
import com.easyder.wrapper.core.model.BaseVo;

import net.gyapp.markim.R;
import net.gyapp.markim.module.basic.base.CommonPresenter;
import net.gyapp.markim.module.collect.UserIntroduceActivity;
import net.gyapp.markim.module.contact.adapter.GroupUserAdapter;
import net.gyapp.markim.module.contact.vo.GroupMemberVo;
import net.gyapp.markim.module.contact.vo.UserVo;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import me.winds.widget.usage.TitleView;

/**
 * Author:  winds
 * Data:    2018/8/22
 * Version: 1.0
 * Desc:
 */


public class GroupMemberActivity extends WrapperSwipeActivity<CommonPresenter> {

    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;

    GroupUserAdapter userAdapter;

    public static Intent getIntent(Context context, List<GroupMemberVo.GroupUsersBean> list, String title) {
        return new Intent(context, GroupMemberActivity.class).putExtra("list", new ArrayList<>(list)).putExtra("title", title);
    }

    @Override
    protected int getViewLayout() {
        return R.layout.common_recycler;
    }

    @Override
    protected void initView(Bundle savedInstanceState, TitleView titleView, final Intent intent) {
        titleView.setCenterText(intent.getStringExtra("title"));
        mRecyclerView.setLayoutManager(new GridLayoutManager(mActivity, 4));
        userAdapter = new GroupUserAdapter();
        mRecyclerView.setAdapter(userAdapter);
        mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                Object item = userAdapter.getItem(position);
                if (item instanceof GroupMemberVo.GroupUsersBean) {
                    UserVo userVo = new UserVo();
                    userVo.userInfo = new UserVo.UserInfoBean();
                    userVo.userInfo.userId = ((GroupMemberVo.GroupUsersBean) item).userId;
                    userVo.userInfo.userName = ((GroupMemberVo.GroupUsersBean) item).userInfo.userName;
                    userVo.userInfo.userNumber = ((GroupMemberVo.GroupUsersBean) item).userInfo.userNumber;
                    userVo.userInfo.nick = ((GroupMemberVo.GroupUsersBean) item).userInfo.nick;
                    userVo.userInfo.phone = ((GroupMemberVo.GroupUsersBean) item).userInfo.phone;
                    userVo.userInfo.userAvatar = ((GroupMemberVo.GroupUsersBean) item).userInfo.userAvatar;

                    startActivity(UserIntroduceActivity.getIntent(mActivity, userVo));
                }
            }
        });

        ArrayList<GroupMemberVo.GroupUsersBean> list = (ArrayList<GroupMemberVo.GroupUsersBean>) intent.getSerializableExtra("list");
        userAdapter.setAdapterData(list);
    }

    @Override
    protected void loadData(Bundle savedInstanceState, Intent intent) {

    }

    @Override
    public void showContentView(String url, BaseVo dataVo) {

    }
}
